package study.nosql.mongodb.dao.userbase;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import study.nosql.mongodb.dao.BaseDao;

import java.util.List;

@Repository
public class UserBaseDao extends BaseDao<UserBaseEO> {

    public UserBaseEO getByUbId(Long ubId) {
        Criteria criteria = Criteria.where("ub_id").is(ubId);
        Query query = new Query(criteria);
        return mongoTemplate.findOne(query, UserBaseEO.class);
    }

    public List<UserBaseEO> getByUbIds(List<Long> ubIdLt) {
        Criteria criteria = Criteria.where("ub_id").in(ubIdLt);
        Query query = new Query(criteria).limit(20);
        return mongoTemplate.find(query, UserBaseEO.class);
    }

    public List<UserBaseEO> getByUbIdss(List<Long> ubIdLt) {
        Criteria criteria = Criteria.where("create_time").gte("startTime").lt("endTime")
                .and("has_delete").is(Boolean.FALSE)
                .and("send_status").ne("SendStatusType.SendSuccess.toString()")
                .and("retry_count").lt("AppConst.MAX_RETRY_COUNT");
        Query query = new Query(criteria).limit(20); //每次取20条

        return mongoTemplate.find(query, UserBaseEO.class);
    }
}
